package com.colortea.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import com.colortea.dao.RoleFunctionMDao;
import com.colortea.entity.RoleFunctionM;
import com.colortea.dao.impl.RoleFunctionMDaoImpl;


@Repository("roleFunctionMDao")
public class RoleFunctionMDaoImpl extends BaseTDaoImpl<RoleFunctionM> implements RoleFunctionMDao {
	private static final Logger log = LoggerFactory.getLogger(RoleFunctionMDaoImpl.class);

	public List<RoleFunctionM> findAllRoleFunctionMByroleid(String roleid) {
		log.debug("findAllRoleFunctionMByroleid");
		try {
			String queryString = "from RoleFunctionM as rfm where rfm.roleid=:roleid";
			Query createQuery = this.getSessionFactory().openSession().createQuery(queryString);
			createQuery.setParameter("roleid", roleid);
			List<RoleFunctionM> list = createQuery.list();
			return list;
		} catch (RuntimeException re) {
			log.error("findAllRoleFunctionMByroleid error", re);
			throw re;
		}
	}

	public int delRoleFunctionM(final String roleid) {
		log.debug("delRoleFunctionM");
		try {

			final String queryString = "delete from RoleFunctionM as rfm where rfm.roleid=:roleid";
			Query query = this.getSessionFactory().openSession().createQuery(queryString);
			int i = 0;
			query.setParameter("roleid", roleid);
			i = query.executeUpdate();
			return i;
		} catch (RuntimeException re) {
			log.error("delFunctionM failed", re);
			throw re;
		}
	}

	
	
	
	
}